<template>
  <view class="image-page">
    <view class="title">显示图片</view>
    <image :src="imageUrl" class="show-image" mode="aspectFit" @click="previewImage"></image>
    <button class="action-btn" @click="chooseImage">选择图片显示</button>
    <button class="action-btn" @click="previewImage">预览图片</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imageUrl: '' 
    };
  },
  methods: {
    chooseImage() {
      uni.chooseImage({
        count: 1, 
        sizeType: ['compressed'], 
        sourceType: ['album', 'camera'], 
        success: (res) => {
          this.imageUrl = res.tempFilePaths[0]; 
        }
      });
    },
    previewImage() {
      if (!this.imageUrl) {
        uni.showToast({
          title: '请先选择图片',
          icon: 'none'
        });
        return;
      }
      uni.previewImage({
        current: this.imageUrl, 
        urls: [this.imageUrl] 
      });
    },

    getImageInfo() {
      if (!this.imageUrl) {
        uni.showToast({
          title: '请先选择图片',
          icon: 'none'
        });
        return;
      }
    }
  }
};
</script>

<style scoped>
.image-page {
  padding: 20rpx;
}
.title {
  font-size: 36rpx;
  font-weight: bold;
  text-align: center;
  margin-bottom: 30rpx;
}
.show-image {
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
  display: block;
  margin: 0 auto 30rpx; /* 实现水平居中 */
}
.action-btn {
  margin-bottom: 20rpx;
}
</style>